﻿
#region NameSpace
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Eb.StockManagement;
using ebird.BusinessProcessAutomationDAS;
#endregion

public partial class Modules_Stock_Management_ProductHistory : System.Web.UI.UserControl
{
    #region Fields
    static string connectionString = "Data Source=198.64.249.24,1092;Initial Catalog=eInternShip;User Id=bmjobmjo;Password=goodhopealways";// ConfigurationManager.ConnectionStrings["connectUserManager"].ToString();
//    string connectionString = ConfigurationManager.ConnectionStrings["connectUserManager"].ToString();
    Eb.StockManagement.StockManagement stockManagement = new Eb.StockManagement.StockManagement();
    ebird.BusinessProcessAutomationDAS.StockManagementDAS stockManagementDAS;


    #endregion

    #region Events
    protected void Page_Load(object sender, EventArgs e)
    {
        stockManagementDAS = new ebird.BusinessProcessAutomationDAS.StockManagementDAS(connectionString);
      
        if (!IsPostBack)
        {
            PopulateBathHistoryGrid();
        }
    }

    protected void grvBatchHistory_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
        #region NameSpace
        int lotId = 0;
        DataSet stockDetailsDS = new DataSet();
        #endregion

        try
        {
            
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                e.Row.Attributes.Add("onmouseover", "MouseEvents(this, event)");

                e.Row.Attributes.Add("onmouseout", "MouseEvents(this, event)");

            } 
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //GridView gv = (GridView)e.Row.FindControl("grvProductMovement");
                //string lblLotId = ((Label)e.Row.FindControl("lblLotID")).Text;
                //if (lblLotId != "")
                //    lotId = Convert.ToInt16(lblLotId);
                //stockDetailsDS = stockManagement.GetProductHistory(lotId);
                //gv.DataSource = stockDetailsDS;
                //gv.DataBind();


                //using 3 tier architecture

                GridView gv = (GridView)e.Row.FindControl("grvProductMovement");
                StockDetails stockData = new StockDetails();
                string lblLotId = ((Label)e.Row.FindControl("lblLotID")).Text;
                stockData.LotID = lblLotId;
                stockDetailsDS = stockManagementDAS.GetProductHistory(stockData);
                gv.DataSource = stockDetailsDS;
                gv.DataBind();


            }
          
            if (e.Row.RowType == DataControlRowType.EmptyDataRow)
                e.Row.CssClass = "grid-view-header";

            if (e.Row.RowType == DataControlRowType.Header)
                e.Row.CssClass = "grid-view-header";

            //Add CSS class on normal row.
            if (e.Row.RowType == DataControlRowType.DataRow &&
                      e.Row.RowState == DataControlRowState.Normal)
                e.Row.CssClass = "grid-view-normal";

            //Add CSS class on alternate row.
            if (e.Row.RowType == DataControlRowType.DataRow &&
                      e.Row.RowState == DataControlRowState.Alternate)
                e.Row.CssClass = "grid-view-alternate";
        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to retrive LotID !";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
      }
    
    #endregion

    #region Methods
    /// <summary>
    /// Populate BathHistory 
    ///
    /// </summary>
    void PopulateBathHistoryGrid()
    {
        try
        {
            //DataSet bathHistoryDS = new DataSet();
            //bathHistoryDS = stockManagement.GetBatchHistory();
            //grvBatchHistory.DataSource = bathHistoryDS;
            //grvBatchHistory.DataBind();

            //Using 3 tier Architecture

            DataSet bathHistoryDS = new DataSet();
            bathHistoryDS = stockManagementDAS.GetBatchHistory();
            grvBatchHistory.DataSource = bathHistoryDS;
            grvBatchHistory.DataBind();

        }
        catch (Exception exp)
        {
            Session["ERRTITLE"] = "Failed to Populate BatchHistory!";
            Session["ERRDET"] = exp.Message;
            Response.Redirect("ErrorPage.aspx");
        }
    }
    #endregion
    protected void grvBatchHistory_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvBatchHistory.PageIndex = e.NewPageIndex;
        PopulateBathHistoryGrid();
    }
    protected void grvBatchHistory_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}
